<?php

require_once ROOT_DIR.'models/Message.php';

/**
 * Tries to create a new message and store it to the db and echos the result.
 * @param string $title
 * @param string $text
 * @param int $messageID
 * @param int $todoID
 * @param int $listID
 * @param int $userID
 */
function newMsg($title, $text, $messageID = '', $todoID = '', $listID = '', $userID = ''){
	$msg = new Message($title, $text, time(), $_SESSION['USER_ID'], $messageID, $todoID, $listID, $userID);
	if($msg->saveToDB()){
		$res = new ResultJSON(false, session_id());
		$res->addItem('mID', $msg->getID());
		echo $res->renderView();
	} else {
		$res = new ResultJSON(true, session_id(), ERROR_ACTION_FAILED);
		echo $res->renderView();
	}
}

?>